﻿@using Think9.Models;
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<script src="~/lib/layui/layui.js" charset="utf-8"></script>
<blockquote class="layui-elem-quote layui-text">
    动态行是指按照设定的读取规则实现行自增长，自增长的每一行被选定的参数将被赋值，参数赋值为单列选择的Value或拆解的字符，如设定从性别选择(单列选择)中读取，将自动增长为两行，第一行参数@@性别被赋值为男（或者1）；第二行参数@@性别被赋值为女（或者2）<br>
    统计表的数据行才能设置为动态行
</blockquote>
<span style="position: absolute;top: 20px; right: 20px;" id="blockquote_close">
    <i class="fa fa-close" style="color: #FFAB00;" id="tipsWhereStr"></i>
</span>
<input style="display:none" id="rpId" value="@ViewBag.RpId">
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script>
    layui.use(["table", "form", "exLayer", "exUtils"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let $ = layui.$;

        form.render(); //

        $("#blockquote_close").click(function () {
            $(".layui-elem-quote").attr("style", "display:none");
            $("#blockquote_close").attr("style", "display:none");
        });

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysStats/ReportDYNParm/GetList?rpId=" + $("#rpId").val(),
            method: "post",
            page: false,
            defaultToolbar: [{ title: '刷新', layEvent: 'refresh', icon: 'layui-bg-gray layui-icon-refresh' }],
            toolbar: "#toolbarTpl",
            cols: [[
                { field: "Postion", title: "位置", width: 150, sort: true },
                { field: "ParameteName", title: "参数", width: 250, sort: true },
                { field: "Type", title: "方式", width: 150, sort: true },
                { field: "RuleName", title: "参数选项" },
                { title: "操作", width: 180, align: "center", fixed: layui.device().mobile ? null : 'right', templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
                case "refresh":
                    refresh();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data.DynamicId);
                    break;
                case "del":
                    del(data.DynamicId);
                    break;
            }
        });

        function add() {
            exLayer.openMiddle("新建动态行", "/SysStats/Report/AddDYNParm?rpId=" + $("#rpId").val(), '500px', '450px', layui.device().mobile);
        }

        function refresh() {
            ThisTable.reload({
                where: { rpId: $("#rpId").val() }
            });
        }

        function edit(id) {
            exLayer.openMiddle("编辑动态行", "/SysStats/Report/EditDYNParm?id=" + id + "&rpId=" + $("#rpId").val(), '500px', '450px', layui.device().mobile);
        }

        function del(id) {
            exLayer.confirm("确定移除该行的动态属性吗？", function () {
                exUtils.ajax("/SysStats/ReportDYNParm/Remove", "get", { id: id }, true).done(function (response) {
                    exUtils.tableSuccessMsg(response.message);
                    ThisTable.reload({
                        where: { rpId: $("#rpId").val() }
                    });
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }
    });</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>新建动态行</button>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id="edit">编辑</a>
    <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-warm" lay-event="del" id="del">移除动态属性</a>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="DataType">
    {{# if(d.DataType == 'DateTime'){ }}
    <span>日期</span> {{# } }}

    {{# if(d.DataType == 'string'){ }}
    <span>字符</span> {{# } }}

    {{# if(d.DataType == 'decimal'){ }}
    <span>小数</span> {{# } }}

    {{# if(d.DataType == 'int'){ }}
    <span>整数</span> {{# } }}
</script>